package com.bawei.liuzhanlin20210806.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bawei.liuzhanlin20210806.R;
import com.bawei.liuzhanlin20210806.model.bean.NrBean;
import com.bawei.liuzhanlin20210806.model.bean.XlBean;
import com.bawei.liuzhanlin20210806.model.utils.HttpUtils;
import com.bawei.liuzhanlin20210806.view.adapter.NrAdapter;
import com.bawei.liuzhanlin20210806.view.adapter.XlAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class Main2Activity extends AppCompatActivity {

    @BindView(R.id.rlv)
    RecyclerView rlv;
    @BindView(R.id.cb_yl)
    TextView cbYl;
    private String strength = "all";
    private String theme = "all";
    private String position = "all";
    private String apparatus = "all";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        ButterKnife.bind(this);
        //展示标题
        HttpUtils.getInstance().getApiService().xlservice(strength, theme, position, apparatus)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<XlBean>() {
                    @Override
                    public void accept(XlBean xlBean) throws Exception {
                        rlv.setLayoutManager(new GridLayoutManager(Main2Activity.this, 2));
                        rlv.setAdapter(new XlAdapter(xlBean.data.result.trains, Main2Activity.this));
                    }
                });
        //点击展示
        cbYl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                apparatus = "哑铃";
                HttpUtils.getInstance().getApiService().nrservice(strength, theme, position, apparatus)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Consumer<NrBean>() {
                            @Override
                            public void accept(NrBean nrBean) throws Exception {
                                rlv.setLayoutManager(new LinearLayoutManager(Main2Activity.this));
                                rlv.setAdapter(new NrAdapter(nrBean.data.result.trains,Main2Activity.this));
                            }
                        });
            }
        });
    }
}
